home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / Mesa / src-glut / glutstuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-02  |  4.7 KB  |  275 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  1.1
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21.  
  22. /*
  23.  * glutstuff.c
  24.  *
  25.  * Version 1.0  27 Jun 1998
  26.  * by Jarno van der Linden
  27.  * jarno@kcbbs.gen.nz
  28.  *
  29.  * Version 1.1  02 Aug 1998
  30.  * by Jarno van der Linden
  31.  * jarno@kcbbs.gen.nz
  32.  *
  33.  * - Quantizer plugin support added
  34.  *
  35.  */
  36.  
  37.  
  38. #include <constructor.h>
  39.  
  40. #include <proto/exec.h>
  41.  
  42. #include "glutstuff.h"
  43.  
  44.  
  45. struct GlutStuff glutstuff;
  46.  
  47. DEFAULT_CONSTRUCTOR(glutConstruct)
  48. {
  49.     glutstuff.msgport = CreateMsgPort();
  50.     if(glutstuff.msgport == NULL)
  51.     {
  52.         return(1);
  53.     }
  54.     glutstuff.curwin = NULL;
  55.     glutstuff.wins = NULL;
  56.     glutstuff.nextwinid = 1;
  57.  
  58.     glutstuff.curmenu = NULL;
  59.     glutstuff.menus = NULL;
  60.     glutstuff.nextmenuid = 1;
  61.  
  62.     glutstuff.initposx = -1;
  63.     glutstuff.initposy = -1;
  64.     glutstuff.initwidth = 300;
  65.     glutstuff.initheight = 300;
  66.  
  67.     glutstuff.numcolours = 248;
  68.     glutstuff.colourbase = 8;
  69.     glutstuff.pubscreenname = "Mesa";
  70.     glutstuff.quantizer = NULL;
  71.     glutstuff.quantizerversion = -1;
  72.  
  73.     glutstuff.rgba = GL_TRUE;
  74.     glutstuff.alpha = GL_FALSE;
  75.     glutstuff.db = GL_FALSE;
  76.     glutstuff.accum = GL_FALSE;
  77.     glutstuff.depth = GL_FALSE;
  78.     glutstuff.stencil = GL_FALSE;
  79.     glutstuff.multisample = GL_FALSE;
  80.     glutstuff.stereo = GL_FALSE;
  81.     glutstuff.luminance = GL_FALSE;
  82.  
  83.     glutstuff.idlefunc = NULL;
  84.     glutstuff.menustatusfunc = NULL;
  85.  
  86.     glutstuff.basetime_secs = 0;
  87.     glutstuff.basetime_micros = 0;
  88.     glutstuff.havebasetime = FALSE;
  89.  
  90.     return(0);
  91. }
  92.  
  93.  
  94. DEFAULT_DESTRUCTOR(glutDestruct)
  95. {
  96.     struct GlutWindow *gw, *gwn;
  97.     struct GlutMenu *gm, *gmn;
  98.  
  99.     gw = glutstuff.wins;
  100.     while(gw)
  101.     {
  102.         gwn = gw->next;
  103.         glutDestroyWindow(gw->winid);
  104.         gw = gwn;
  105.     }
  106.  
  107.     gm = glutstuff.menus;
  108.     while(gm)
  109.     {
  110.         gmn = gm->next;
  111.         glutDestroyMenu(gm->menuid);
  112.         gm = gmn;
  113.     }
  114.  
  115.     if(glutstuff.msgport)
  116.         DeleteMsgPort(glutstuff.msgport);
  117. }
  118.  
  119.  
  120. int stuffGetNewWinID(void)
  121. {
  122.     return(glutstuff.nextwinid++);
  123. }
  124.  
  125.  
  126. struct GlutWindow *stuffGetWin(int winid)
  127. {
  128.     struct GlutWindow *gw;
  129.  
  130.     gw = glutstuff.wins;
  131.     while(gw && (gw->winid != winid))
  132.         gw = gw->next;
  133.  
  134.     return(gw);
  135. }
  136.  
  137.  
  138. void stuffLinkInWin(struct GlutWindow *gw)
  139. {
  140.     gw->next = glutstuff.wins;
  141.     gw->prev = NULL;
  142.     if(glutstuff.wins)
  143.         glutstuff.wins->prev = gw;
  144.     glutstuff.wins = gw;
  145.  
  146.     stuffMakeCurrent(gw);
  147. }
  148.  
  149.  
  150. void stuffLinkOutWin(struct GlutWindow *gw)
  151. {
  152.     if(gw->prev)
  153.         gw->prev->next = gw->next;
  154.     if(gw->next)
  155.         gw->next->prev = gw->prev;
  156.  
  157.     if(glutstuff.wins == gw)
  158.         glutstuff.wins = gw->next;
  159.  
  160.     if(glutstuff.curwin == gw)
  161.         glutstuff.curwin = NULL;
  162. }
  163.  
  164.  
  165. void stuffMakeCurrent(struct GlutWindow *gw)
  166. {
  167.     if(glutstuff.curwin != gw)
  168.     {
  169.         glutstuff.curwin = gw;
  170.  
  171.         AmigaMesaRTLMakeCurrent(gw->context);
  172.     }
  173. }
  174.  
  175.  
  176. int stuffGetNewMenuID(void)
  177. {
  178.     return(glutstuff.nextmenuid++);
  179. }
  180.  
  181.  
  182. struct GlutMenu *stuffGetMenu(int menuid)
  183. {
  184.     struct GlutMenu *gm;
  185.  
  186.     gm = glutstuff.menus;
  187.     while(gm && (gm->menuid != menuid))
  188.         gm = gm->next;
  189.  
  190.     return(gm);
  191. }
  192.  
  193.  
  194. void stuffLinkInMenu(struct GlutMenu *gm)
  195. {
  196.     gm->next = glutstuff.menus;
  197.     gm->prev = NULL;
  198.     if(glutstuff.menus)
  199.         glutstuff.menus->prev = gm;
  200.     glutstuff.menus = gm;
  201.  
  202.     stuffMakeCurrentMenu(gm);
  203. }
  204.  
  205.  
  206. void stuffLinkOutMenu(struct GlutMenu *gm)
  207. {
  208.     if(gm->prev)
  209.         gm->prev->next = gm->next;
  210.     if(gm->next)
  211.         gm->next->prev = gm->prev;
  212.  
  213.     if(glutstuff.menus == gm)
  214.         glutstuff.menus = gm->next;
  215.  
  216.     if(glutstuff.curmenu == gm)
  217.         glutstuff.curmenu = NULL;
  218. }
  219.  
  220.  
  221. void stuffMakeCurrentMenu(struct GlutMenu *gm)
  222. {
  223.     if(glutstuff.curmenu != gm)
  224.     {
  225.         glutstuff.curmenu = gm;
  226.     }
  227. }
  228.  
  229.  
  230. struct GlutMenuEntry *stuffGetMenuEntry(int entry,struct GlutMenu *gm)
  231. {
  232.     struct GlutMenuEntry *gme;
  233.  
  234.     gme = gm->entries;
  235.     entry--;
  236.  
  237.     for(;entry > 0; entry--)
  238.         gme = gme->next;
  239.  
  240.     return(gme);
  241. }
  242.  
  243.  
  244. void stuffLinkInMenuEntry(struct GlutMenuEntry *gme,struct GlutMenu *gm)
  245. {
  246.     struct GlutMenuEntry *p;
  247.  
  248.     for(p=gm->entries; p && p->next; p=p->next)
  249.         ;
  250.     gme->next = NULL;
  251.     gme->prev = p;
  252.     if(p)
  253.         p->next = gme;
  254.     else
  255.         gm->entries = gme;
  256.     gm->numentries++;
  257.     gme->menu = gm;
  258. }
  259.  
  260.  
  261. void stuffLinkOutMenuEntry(struct GlutMenuEntry *gme,struct GlutMenu *gm)
  262. {
  263.     if(gme->prev)
  264.         gme->prev->next = gme->next;
  265.     if(gme->next)
  266.         gme->next->prev = gme->prev;
  267.  
  268.     if(gm->entries == gme)
  269.         gm->entries = gme->next;
  270.  
  271.     gm->numentries--;
  272.  
  273.     gme->menu = NULL;
  274. }
  275.